package com.fulei.device;

import com.bjfl.saleManager.util.LogUtil;
import com.fulei.logic.FuLeiKeyOperate;

public class KeyDevice
{
  private String deviceType;
  private String comNo;
  private String baudRate;
  
  public KeyDevice(String devType, String com, String brn)
  {
    this.deviceType = devType;
    this.comNo = com;
    this.baudRate = brn;
  }
  
  public int ResetKey()
  {
    int return_data = 0;
    try
    {
      if ("FULEIKEY1".equals(this.deviceType))
      {
        FuLeiKeyOperate.comNo = this.comNo;
        FuLeiKeyOperate.baudRate = this.baudRate;
        
        return_data = FuLeiKeyOperate.ResetKey();
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("复位按键:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int QueryKey()
  {
    int return_data = 0;
    try
    {
      if ("FULEIKEY1".equals(this.deviceType))
      {
        FuLeiKeyOperate.comNo = this.comNo;
        FuLeiKeyOperate.baudRate = this.baudRate;
        
        return_data = FuLeiKeyOperate.QueryKey();
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("查询按键状态:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int outControlInfo()
  {
    int return_data = 0;
    try
    {
      return_data = FuLeiKeyOperate.ControlPanel();
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("传感器异常:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int FlashKey(int flashVal)
  {
    int return_data = 0;
    try
    {
      if ("FULEIKEY1".equals(this.deviceType))
      {
        FuLeiKeyOperate.comNo = this.comNo;
        FuLeiKeyOperate.baudRate = this.baudRate;
        
        return_data = FuLeiKeyOperate.FlashKey(flashVal);
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("按键闪灯:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int GoodsFlashKey()
  {
    int return_data = 0;
    try
    {
      if ("FULEIKEY1".equals(this.deviceType))
      {
        FuLeiKeyOperate.comNo = this.comNo;
        FuLeiKeyOperate.baudRate = this.baudRate;
        
        return_data = FuLeiKeyOperate.GoodsFlashKey();
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("按键闪灯:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int PayoutFlashKey()
  {
    int return_data = 0;
    try
    {
      if ("FULEIKEY1".equals(this.deviceType))
      {
        FuLeiKeyOperate.comNo = this.comNo;
        FuLeiKeyOperate.baudRate = this.baudRate;
        
        return_data = FuLeiKeyOperate.PayoutFlashKey();
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("找币口闪灯:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
}
